package com.uex.dev.manage.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.query.MPJQueryWrapper;
import com.google.common.base.Preconditions;
import com.uex.dev.manage.admin.dao.ModelRobotDao;
import com.uex.dev.manage.admin.po.ModelRobotPO;
import com.uex.dev.manage.admin.service.IModelRobotService;
import com.uex.dev.manage.admin.vo.device.RobotInfo;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 * 收单机型号默认能力 仅内部用户查看 服务实现类
 * </p>
 *
 * @author wangchao
 * @since 2024-04-11
 */
@Service
public class ModelRobotServiceImpl extends ServiceImpl<ModelRobotDao, ModelRobotPO> implements IModelRobotService {

    @Override
    public RobotInfo getRobotFeature(Integer modelId) {
        RobotInfo robotInfo = this.selectJoinOne(RobotInfo.class, new MPJQueryWrapper<ModelRobotPO>()
                .select("t.*, tdm.device_model")
                .leftJoin("t_device_model tdm on tdm.id = t.model_id")
                .eq("t.model_id", modelId));
        Preconditions.checkArgument(Objects.nonNull(robotInfo), "型号Id不存在");
        return robotInfo;
    }

    @Override
    public void updateRobotFeature(RobotInfo robotModelUpdateReq) {
        ModelRobotPO modelRobot = robotModelUpdateReq.toModelRobotPO();
        Preconditions.checkArgument(this.updateById(modelRobot), "型号Id不存在");
    }
}
